package com._13read.rss.controller.mp;

import com._13read.rss.entity.RssEntry;
import com._13read.rss.manager.IRssManager;
import com._13read.rss.model.MyPage;
import com._13read.rss.service.IRssEntryService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mp/api/v1/rss")
public class RssController {

    @Autowired
    private IRssManager rssManager;
    @Autowired
    private IRssEntryService rssEntryService;

    @GetMapping("/add")
    public void add(String url){
        rssManager.addSource(url);
        return;
    }

    @GetMapping("/list")
    public String get(Long id,Long current){
        MyPage<RssEntry> rssEntryMyPage = rssEntryService.basicInfoByRssSourceId(id, current);
        return JSONObject.toJSONString(rssEntryMyPage.getRecords());
    }

    @GetMapping("/get")
    public String get(Long id){
        RssEntry byId = rssEntryService.getById(id);
        return JSONObject.toJSONString(byId);
    }

}
